home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / local / themeSelection.php < prev    next >
PHP Script  |  2010-05-19  |  18KB  |  459 lines

  1. <?php
  2. /**
  3.  * Theme selection interface
  4.  *
  5.  *
  6.  * PHP version 5
  7.  *
  8.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category   NA
  15.  * @package    NA
  16.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  17.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  18.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19.  * @version    CVS: $Id:$
  20.  * @link       http://www.weezo.net
  21.  * @since      File available since Release 1.0.9
  22.  */
  23.  
  24.  
  25. if(!cfIsInApp()) die();
  26.  
  27.  
  28. /**
  29.  * @desc echo async js script that update thumbnail position and src
  30.  *
  31.  * @param string $theme
  32.  */
  33. function themeSelectionThumbnailAsyncUpdate($theme=false){
  34.     if(!$theme) $theme=cfGGetVar('theme');
  35.  
  36.     // Update $wallpaper && $wallpaperPosition
  37.     list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper($theme);
  38.     echo cfAsyncXMLJSaction('setWallpaper("'.$theme.'","'.(($wallpaper)?$wallpaperPosition:'').'")');
  39. }
  40.  
  41. /**
  42.  * @desc unlink all background images for selected theme
  43.  *
  44.  * @param string $theme
  45.  */
  46. function themeSelectionClearImages($theme=false){
  47.     if(!$theme) $theme=cfGGetVar('theme');
  48.  
  49.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.jpg');
  50.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.jpg');
  51.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.jpg');
  52.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.gif');
  53.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.gif');
  54.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.gif');
  55.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.png');
  56.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.png');
  57.     @unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.png');
  58. }
  59.  
  60. /**
  61.  * @desc Echo image of preview
  62.  *
  63.  */
  64. function themeSelectionPreviewThumbnail(){
  65.     WHeaders::noCache();
  66.     WHeaders::contentType('image/jpeg');
  67.  
  68.     $wpTheme=cfGGetVar('theme');
  69.     list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper();
  70.     cfCreateResizedJPG(cfAppDocRoot().$wallpaper,0,0,'',120,60);
  71.     exit;
  72. }
  73.  
  74. /**
  75.  * Return array (wallpaper src (false if no wallpaper) / wallpaper position (centered/tiled/stretched) for a given theme
  76.  *
  77.  * @param string $theme
  78.  * @return array(string,string)
  79.  */
  80. function themeSelectionGetWallpaper($theme=false){
  81.     if(!$theme) $theme=cfGGetVar('theme');
  82.  
  83.     $wallpaper=false;
  84.     $wallpaperPosition='centered';
  85.     if(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.jpg')){$wallpaper='/themes/'.$theme.'/wallpaper-centered.jpg'; $wallpaperPosition='centered';}
  86.     elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.jpg')){$wallpaper='/themes/'.$theme.'/wallpaper-stretched.jpg'; $wallpaperPosition='stretched';}
  87.     elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.jpg')){$wallpaper='/themes/'.$theme.'/wallpaper-tiled.jpg'; $wallpaperPosition='tiled';}
  88.     if(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.gif')){$wallpaper='/themes/'.$theme.'/wallpaper-centered.gif'; $wallpaperPosition='centered';}
  89.     elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.gif')){$wallpaper='/themes/'.$theme.'/wallpaper-stretched.gif'; $wallpaperPosition='stretched';}
  90.     elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.gif')){$wallpaper='/themes/'.$theme.'/wallpaper-tiled.gif'; $wallpaperPosition='tiled';}
  91.     if(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.png')){$wallpaper='/themes/'.$theme.'/wallpaper-centered.png'; $wallpaperPosition='centered';}
  92.     elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.png')){$wallpaper='/themes/'.$theme.'/wallpaper-stretched.png'; $wallpaperPosition='stretched';}
  93.     elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.png')){$wallpaper='/themes/'.$theme.'/wallpaper-tiled.png'; $wallpaperPosition='tiled';}
  94.  
  95.     return array($wallpaper,$wallpaperPosition);
  96. }
  97.  
  98. /**
  99.  * Process POST commands
  100.  *
  101.  */
  102. function themeSelectionProcessCommands(){
  103.     global $themes;
  104.     global $wpTheme;
  105.  
  106.  
  107.     /*
  108.      * Wallpaper upload processing
  109.      */
  110.     if(isset($_POST['position']) && isset($_FILES['wallpaperUpload'])) {
  111.         // new image sent
  112.         if(strlen($_FILES['wallpaperUpload']['name']) && !empty($_FILES['wallpaperUpload']['tmp_name']) && is_uploaded_file($_FILES['wallpaperUpload']['tmp_name'])){
  113.             // Check uploaded image format from name
  114.             if($_FILES['wallpaperUpload']['type']!='image/jpeg' && $_FILES['wallpaperUpload']['type']!='image/pjpeg' && $_FILES['wallpaperUpload']['type']!='image/gif' && $_FILES['wallpaperUpload']['type']!='image/png') die(cfAsyncFooter());
  115.             elseif($_POST['position']=='centered' || $_POST['position']=='stretched' || $_POST['position']=='tiled'){
  116.                 $tmpFile=cfAppDocRoot().'/themes/'.$wpTheme.'/wallpaper-temp.'.cfFileExtension($_FILES['wallpaperUpload']['name']);
  117.                 $destFile=cfAppDocRoot().'/themes/'.$wpTheme.'/wallpaper-'.$_POST['position'].'.'.((cfFileExtension($_FILES['wallpaperUpload']['name'])=='jpeg')?'jpg':cfFileExtension($_FILES['wallpaperUpload']['name']));
  118.                 @unlink($tmpFile);
  119.  
  120.                 if(move_uploaded_file($_FILES['wallpaperUpload']['tmp_name'], $tmpFile)){
  121.                     @unlink($destFile);
  122.                     // Copy uploaded wallpaper
  123.                     rename($tmpFile, $destFile);
  124.                 }
  125.             }
  126.         }
  127.         // no new image
  128.         else{
  129.             // Change current wallpaper position
  130.             if($wallpaper && $_POST['position']=='centered' || $_POST['position']=='stretched' || $_POST['position']=='tiled'){
  131.                 @rename(cfAppDocRoot().$wallpaper,cfAppDocRoot().'/themes/'.$wpTheme.'/wallpaper-'.$_POST['position'].'.'.cfFileExtension($wallpaper));
  132.             }
  133.         }
  134.     }
  135.  
  136.  
  137.     // Async commands
  138.     if(!cfIsAsync()) return;
  139.     echo cfAsyncHeader();
  140.  
  141.     /**
  142.      * Change theme
  143.      */
  144.     if(isset($_POST['setTheme']) && ($_POST['setTheme']=='no' || isset($themes[$_POST['setTheme']]))){
  145.         if($_POST['setTheme']=='-') $_POST['setTheme']='';
  146.  
  147.         // General theme
  148.         if($_POST['userFile']=='' || $_POST['userFile']=='general'){
  149.             cfGUpdateVar('theme',$_POST['setTheme'],true);
  150.             // Update client-side thumbnail
  151.             themeSelectionThumbnailAsyncUpdate();
  152.         }
  153.         // User theme
  154.         elseif (WEnv::userConfigs($_POST['userFile'])){
  155.             $uc=new WUserConfig($_POST['userFile']);
  156.  
  157.             if($uc->isValid()){
  158.                 // Modify current user config
  159.                 if(cfIsInApp()) $uc->setVar('theme',($_POST['setTheme']=='no')?'':$_POST['setTheme']);
  160.  
  161.                 // Single user account: commit to user configuration
  162.                 if(cfIsInApp() || cfUGetVar('accountType')=='singleUser') $uc->save();
  163.                 if(WEnv::user()) WEnv::user()->setVar('theme',$_POST['setTheme']);
  164.  
  165.                 // Logged user: reload desktop
  166.                 //echo cfAsyncXMLJSaction('winMe.reloadDesktop()');
  167.             }
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * Change login type
  173.      */
  174.     if(isset($_POST['loginForm'])){
  175.         if($_POST['loginForm']=='classic' || $_POST['loginForm']=='coverflow') cfGUpdateVar('loginForm',$_POST['loginForm'],true);
  176.     }
  177.  
  178.     /**
  179.      * Change Wallpaper position
  180.      */
  181.     if(isset($_POST['setPosition'])){
  182.         $pos=$_POST['setPosition'];
  183.         $wpTheme=cfGGetVar('theme');
  184.         list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper();
  185.         $srcFile=cfAppDocRoot().$wallpaper;
  186.         if(is_file($srcFile) && ($pos==='centered' || $pos==='tiled' || $pos==='stretched')){
  187.             $destFile=dirname($srcFile).'/wallpaper-'.$pos.'.'.cfFileExtension($srcFile);
  188.             if($destFile!==$srcFile) @unlink($destFile);
  189.             @rename($srcFile,$destFile);
  190.             themeSelectionThumbnailAsyncUpdate();
  191.         }
  192.         elseif ($pos==='no') themeSelectionClearImages($wpTheme);
  193.     }
  194.  
  195.     // Close window on double click
  196.     if(@$_POST['close']) echo cfAsyncJSaction('wl.UICommand(\'close:'.@$_POST['setTheme'].'\')');
  197.  
  198.     die(cfAsyncFooter());
  199. }
  200.  
  201. /**
  202.  * @desc Display login type selection form
  203.  *
  204.  */
  205. function themeSelectionLoginTypeSelection(){
  206.     echo outDivFrame('frame1');
  207.     echo '<div class="frame1Header">'.outImageIcon('lock').cfCaption('loginPage').'</div>';
  208.     echo outDivFrame('frame2','','text-align:center');
  209.  
  210.     // Classic login
  211.     echo outBlockItem('loginForm',outImage(outIcon('loginFormClassic')),'ondblclick="selectLoginType(\'classic\',1)"','',array('onclick'=>'selectLoginType(\'classic\')'),(cfGGetVar('loginForm')!=='coverflow')?'sel':'unsel')."\n";
  212.  
  213.     // Coverflow login
  214.     echo outBlockItem('loginForm',outImage(outIcon('loginFormCoverflow')),'ondblclick="selectLoginType(\'coverflow\',1)"','',array('onclick'=>'selectLoginType(\'coverflow\')'),(cfGGetVar('loginForm')==='coverflow')?'sel':'unsel');
  215.     ?>
  216.     </div>
  217.     </div>
  218.     <br>
  219.     <br>
  220. <?php
  221. }
  222.  
  223. /**
  224.  * @desc Display wallpaper selection form
  225.  *
  226.  */
  227. function themeSelectionWallpaperSelection(){
  228.     global $wallpaper, $wallpaperPosition;
  229.  
  230.     echo outDivFrame('frame1',false,'margin-top:10px');
  231.     echo '<div class="frame1Header">'.outImage(outIcon('wallpaper'),false,false,'margin-right:1em; vertical-align:middle').cfCaption('genWallpaper').'</div>';
  232.  
  233.  
  234.     // No image
  235.     echo outDivFrame('frame2');
  236.     echo '<input type="radio" id="noUse" name="useWallpaper" value="no"'.(($wallpaper)?'':' checked="checked"').' onclick="setWallpaper();setPosition(\'no\')"><span style="cursor:default" onclick="dgi(\'noUse\').checked=true;setWallpaper();setPosition(\'no\')">'.cfCaption('configWPNo').'</span><br/>';
  237.     echo '</div>';
  238.  
  239.     // Send image
  240.     echo outDivFrame('frame2');
  241. ?>
  242. <input type="radio" id="doUse" name="useWallpaper" value="yes"<?php echo ((!$wallpaper)?'':' checked="checked"'); ?> onclick=""><span style="cursor:default" onclick="dgi('doUse').checked=true"><?php echo cfCaption('configSelectWallpaper'); ?></span>
  243. <br/>
  244. <br/>
  245. <?php // Image upload control ?>
  246. <form name="wallpaperUploadForm" method="POST" enctype="multipart/form-data" style="margin:0;padding:0">
  247. <input onchange="uploadWallpaper()" type="file" id="wallpaperUpload" name="wallpaperUpload" accept="image/gif,image/jpeg" size=7>
  248.  
  249. <div class="warning" id="wallpaperUploadWarning" style="visibility:hidden">
  250. <?php echo outImageIcon('warning').cfCaption('explorerFormatError'); ?>
  251. </div>
  252.  
  253.  
  254. <div id="imagePositionControls" style="width:100%">
  255.  
  256. <div id="preview" style="background:url(/gfx/screenBg.jpg) no-repeat;position:relative;width:160px;height:100px;margin-right:10px;float:left;border:1px solid #AAA;overflow:hidden;text-align:center;white-space:nowrap"></div>
  257.  
  258. <?php //Position selection controls ?>
  259. <input type="radio" onclick="setPosition(this.value)" id="pc" name="position" value="centered"<?php echo (($wallpaperPosition=='centered')?' checked="checked"':''); ?>><?php echo cfCaption('configWPCentered'); ?><br>
  260. <input type="radio" onclick="setPosition(this.value)" id="pt" name="position" value="tiled"<?php echo (($wallpaperPosition=='tiled')?' checked="checked"':''); ?>><?php echo cfCaption('configWPTiled'); ?><br>
  261. <input type="radio" onclick="setPosition(this.value)" id="ps" name="position" value="stretched"<?php echo (($wallpaperPosition=='stretched')?' checked="checked"':''); ?>><?php echo cfCaption('configWPStretched')?>
  262. <br clear="all"> 
  263. </div>
  264.  
  265. </form>
  266. </div>
  267. </div>
  268. <?php
  269. }
  270.  
  271.  
  272. // Init themes list
  273. $themes=cfMGetVar('weezoThemes');
  274. foreach ($themes as $id=>$theme) if(@$theme['private']) unset($themes[$id]); else $themes[$id]['name']=cfUTF8Encode($id);
  275.  
  276.  
  277. // $userFile: set theme level: user or general
  278. if(isset($_POST['userFile'])) $userFile=$_POST['userFile'];
  279. elseif(isset($_GET['userFile'])) $userFile=$_GET['userFile'];
  280. else $userFile=false;
  281.  
  282. // General config
  283. if(!$userFile || $userFile=='general'){
  284.     $userFile='general';
  285.     $wpTheme=cfGGetVar('theme');
  286.     $themeLevel='general';
  287. }
  288. // User config
  289. elseif($user=WENV::userConfigs($userFile)){
  290.     $wpTheme=$user->getVar('theme');
  291.     if(!$wpTheme) $wpTheme='no';
  292.     $themeLevel='user';
  293.     $wallpaperPosition='';
  294. }
  295. else outDisplayErrorPage(cfCaption('configInvalidFile'));
  296.  
  297.  
  298. /*
  299.  ***************************************************************************************************************************
  300.  * Thumbnail image
  301.  ***************************************************************************************************************************
  302.  */
  303. if(isset($_GET['previewThumbnail']) && count($_POST)==0) themeSelectionPreviewThumbnail();
  304.  
  305.  
  306. /*
  307.  ***************************************************************************************************************************
  308.  * Process POST commands
  309.  ***************************************************************************************************************************
  310.  */
  311. themeSelectionProcessCommands();
  312.  
  313. /*
  314.  ***************************************************************************************************************************
  315.  * HEAD, CSS & JS
  316.  ***************************************************************************************************************************
  317.  */
  318. cfInsertHEAD(false);
  319. echo '<meta width="'.(($themeLevel=='general')?'800x550':'675x420').'"></meta>';
  320. echo '<meta icon="theme"></meta>';
  321. echo '<meta title="'.cfCaption('genTheme').'"></meta>';
  322. echo cfScriptLink('winClient.js');
  323. ?>
  324. </head>
  325. <body style="overflow:hidden">
  326. <?php
  327. require_once(INCLUDE_DIR.'outputFunctions.php');
  328.  
  329.  
  330. /*
  331.  ***************************************************************************************************************************
  332.  * Display themes thumbnails
  333.  ***************************************************************************************************************************
  334.  */
  335.  
  336. echo outDivFrame('frame1','',($themeLevel=='general')?'float:left;width:490px':'');
  337. echo '<div class="frame1Header">'.outImageIcon('theme').cfCaption('genTheme').'</div>';
  338. echo outDivFrame('frame2',false,'height:510px;overflow:auto');
  339.  
  340. /**
  341.  * If user-level or resource-level theme, add a "default theme" box
  342.  */
  343. if($themeLevel!='general') {
  344.     $themes=array('no'=>array('name'=>cfCaption('genDefault')))+$themes;
  345. }
  346.  
  347. foreach ($themes as $key=>$theme) {
  348.     $o='';
  349.  
  350.     // Default theme: replace preview by general-level theme's preview
  351.     if($key=='no' && isset($themes[cfGGetVar('theme')])){
  352.         $theme=@$themes[cfGGetVar('theme')];
  353.         $theme['name']=cfCaption('genDefault');
  354.         $theme['faded']=true;
  355.     }
  356.  
  357.     // Preview thumbnail
  358.     if(file_exists(@$theme['dir'].'/thumbnail.png')) $o.='<img src="'.$theme['path'].'/thumbnail.png" style="width:125px;height:94px;'.((isset($theme['faded']))?outCssOpacity(50):'').'"><br>';
  359.     // No preview
  360.     else $o.='<img src="/gfx/screenBg.jpg" style="width:125px;height:94px"><br>';
  361.  
  362.     $o.='<div style="position:absolute;bottom:15px;width:100%;text-align:center;font-size:150%" class="textShadow">'.ucfirst($theme['name']).'</div>';
  363.  
  364.     echo str_replace('<','<',outBlockItem('themes',$o,'id="'.$key.'" ondblclick="selectTheme(\''.$key.'\',1)"','padding:9px',array('onclick'=>'selectTheme(\''.$key.'\')'),($wpTheme===$key)?'sel':'unsel')."\n");
  365. }
  366.  
  367. echo '</div>';
  368. echo '</div>';
  369.  
  370.  
  371. /*
  372.  ***************************************************************************************************************************
  373.  * Display login page selection control
  374.  ** *************************************************************************************************************************
  375.  */
  376. if($themeLevel=='general') themeSelectionLoginTypeSelection();
  377.  
  378.  
  379.  
  380. /*
  381.  ***************************************************************************************************************************
  382.  * Display wallpaper selection control
  383.  ***************************************************************************************************************************
  384.  */
  385. // Retreive wallpaper src & position
  386. list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper();
  387. if($themeLevel=='general') themeSelectionWallpaperSelection();
  388.  
  389. // Close button
  390. if($themeLevel=='general'){
  391. ?>
  392. <br><br><br><br><br><br>
  393. <center>
  394. <?php echo outBt(cfCaption('genClose'),outIcon('closeOK'),'javascript:wl.UICommand(\'close\')',false,false,false,'up',160); ?>
  395. </center>
  396. <?php
  397. }
  398.  
  399. // Scripts
  400. ?>
  401. <script type="text/javascript">
  402. var userFile="<?php echo $userFile ?>";
  403. function init(){
  404.     setWallpaper("<?php echo $wpTheme;?>","<?php if($wallpaper) echo $wallpaperPosition;?>");
  405. }
  406.  
  407. function selectLoginType(lt,close){
  408.     wl.asr.send({'loginForm':lt,'close':(close)?1:0})
  409. }
  410. function selectTheme(t,close){
  411.     wl.asr.send({'setTheme':t,'userFile':userFile,'close':(close)?1:0})
  412. }
  413. function uploadWallpaper(){
  414.     var i=dgi('wallpaperUpload').value.toLowerCase();
  415.  
  416.     if(i.substr(i.length-4)!='.gif' && i.substr(i.length-4)!='.jpg' && i.substr(i.length-5)!='.jpeg' && i.substr(i.length-4)!='.png')
  417.         dgi('wallpaperUploadWarning').style.visibility='';
  418.     else{
  419.         dgi('wallpaperUploadWarning').style.visibility='hidden';
  420.         D.wallpaperUploadForm.submit();
  421.     }
  422. }
  423. function setPosition(pos){
  424.     wl.asr.send({'setPosition':pos})
  425. }
  426.  
  427. function setWallpaper(t,pos){
  428.     var c=dgi("preview"),i,e,l=['pc','pt','ps'];
  429.     if(!c) return;
  430.     var img='<img alt="" src="<?php echo $_SERVER['PHP_SELF'];?>?r='+Math.random()+'&theme='+t+'&previewThumbnail=1';
  431.     if(pos){
  432.         img+='&previewPos='+pos+'"';
  433.         switch(pos){
  434.             case 'stretched':
  435.                 img=img+' style="width:100%;height:100%">';
  436.                 break;
  437.             case 'centered':
  438.                 c.style.textAlign='center'
  439.                 img=img+' style="height:60px;margin-top:20px">';
  440.                 break;
  441.             case 'tiled':
  442.                 img+='>';
  443.                 img=img+img+img+'<br>'+img+img+img;
  444.                 c.style.textAlign='left'
  445.                 break;
  446.         }
  447.         dgi('doUse').checked=true;
  448.     }
  449.     else{
  450.         img='';
  451.         dgi('noUse').checked=true;
  452.     }
  453.     setAlpha(dgi('imagePositionControls'),(pos)?1:0.5);
  454.     setAlpha(dgi('preview'),(pos)?1:0.5);
  455.     c.innerHTML=img;
  456.     for(i=1;i<l.length;i++) dgi(l[i]).disabled=(pos)?false:true;
  457. }
  458. init();
  459. </script>